<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>箱规查询</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<!-- jQuery-->
		<script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>

		<!-- layui-->
		<link rel="stylesheet" href="/static/plugins/layui/2.7.6/css/layui.css" media="all">
		<script src="/static/plugins/layui/2.7.6/layui.js" charset="utf-8"></script>

		<!-- common -->
		<link rel="stylesheet" href="/static/admin/css/common.css" media="all" />
		<link rel="stylesheet" href="/static/admin/css/mini-ease.css" media="all" />

		<!--样式-->
		<th:block th:include="include/src :: form_base_js_and_css"/>

		<style>
			/*隐藏横向滚动条*/
			.hide-scrollbar{
				-ms-overflow-style: none; /* 针对IE和Edge */
				scrollbar-width: none; /* 针对Firefox */
			}
		</style>

	</head>

	<body>



	<form class="layui-form">

		<!--头部按钮-->
		<div class="margin_2_0 height_56 line_height_56 width_percent_100 z_index_1000">
			<div class="bg_color_white height_56 left_0 line_height_56 position_fixed top_0 width_percent_100 z_index_1000">
				<div id="topBtn" class="layui-inline" style="margin-left: 10px; vertical-align: middle; height: 56px; line-height: 56px; padding: 2px 0;">
					<button  type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit onclick="formSubmit()" data-id="id_btn_save">
						<i class="iconfont icon-save"></i>保存
					</button>


				</div>
				<div style="width: 100%;padding-left: 5%;">
					<span id="topTip" style="text-align: center;color: #ffb800;font-size: 18px;"></span>
				</div>


			</div>
		</div>


		<!--头部列表信息-->
		<div class="height_percent_100 margin_2_0 padding_2_0 width_percent_100" style="max-height: calc(100vh - 120px); overflow: unset;">
			<div style="background-color: #ffffff; overflow: unset;">
				<div class="layui-form-item">
					<!--箱子数量-->
					<div class="layui-inline layui-col-xs4 margin_r_0">
						<label class="layui-form-label padding_6_0 width_160 margin_0_0_0_N10"><font class="f_red">*</font>箱子数量：</label>
						<div class="layui-input-block margin_l_150 min_height_38">
							<input type="number" id="boxNum" name="boxNum" value="" onchange="boxNumChangeAndReload();" autocomplete="off" lay-verify="required" class="layui-input height_30 height_30" >
						</div>
					</div>

					<!--装箱人-->
					<div class="layui-inline layui-col-xs4 margin_r_0">
						<label class="layui-form-label padding_6_0 width_160 margin_0_0_0_N10"><font class="f_red">*</font>装箱人：</label>
						<div class="layui-input-block margin_l_150 min_height_38">
							<input readonly type="text" name="boxUpUserName" id="boxUpUserName" value="" class="layui-input height_30 buttontext" lay-verify="required">
							<i style="position: absolute; right: 2px; top:0px; height: 30px; line-height: 30px; width: 25px;" class="layui-icon layui-icon-more" onclick="chooseModel()"></i>
						</div>
					</div>

					<!--按钮-->
					<div class="layui-inline layui-col-xs4 margin_r_0">
						<button type="button" class="layui-btn layui-bg-blue layui-btn-sm" style="margin-left: 20px;" onclick="autoInputNumBtn();" id="autoInputNum">
							<i class="layui-icon layui-icon-edit layui-font-12"></i> 平均装箱
						</button>

						<button type="button" class="layui-btn layui-btn-sm" onclick="americanChange();" id="americanChangeBtn">
							<i class="layui-icon layui-icon-note layui-font-12"></i> <span id="americanChangeBtnTxt">美规界面</span>
						</button>

					</div>

				</div>
			</div>
		</div>

	</form>
	<!-- 列表 -->
	<div class="layui-row layui-col-space5" style="width:90%;margin: 0 auto;">

		<div class="layui-col-md12" id="id_panel_left_grid">
			<div class="layui-panel" style="overflow: auto; padding-top: 0.2rem;">
				<div class="mid-content">

					<table class="layui-hide" id="main_table" lay-filter="main_table"></table>

					<table class="layui-hide" id="box_table" lay-filter="box_table"></table>


					<script type="text/html" id="toolbarDemo">
						<div class="layui-row" style="height: 40px;" id="toolbarDemoBtn">
							<div class="layui-col-xs12">
								<button type="button" class="layui-btn layui-bg-blue layui-btn-sm"  lay-event="add-data" lay-on="add-data" id="addBtn">
									<i class="layui-icon layui-icon-add-1 layui-font-12"></i> 新增
								</button>
                                <button type="button" class="layui-btn layui-btn-danger layui-btn-sm"  lay-event="del-data" lay-on="del-data">
                                    <i class="layui-icon layui-icon-delete layui-font-12"></i> 删除
                                </button>
							</div>

						</div>
					</script>
				</div>
			</div>
		</div>
	</div>


	<div style="width: 80%;">
		<div id="printTip" style="color: #ffb800;font-size: 16px;padding-left: 5%;padding-top: 10px;"></div>
	</div>
	<div style="height: 30px;width: 100%;"></div>

	<input type="hidden" name="boxUpUserId" id="boxUpUserId" value=""><!--装箱人用户工号-->
	<input type="hidden" name="bid" id="bid" value=""><!--单号-->

      <script>
		  $('#topBtn').hide();


		  $('#bid').val('[(${bid})]');//单号
		  var tableId = '[(${tableId})]';
		  var isSearch = '[(${isSearch})]';
		  var isEdit = 0;

		  var boxNumMax = 0;
		  var dataList = [];
		  var dataListByBox = [];

		  var americanChangeIsOpen = 0;//美规页面是否开启

		  //获取列表数据
		  $.ajax({
			  url : '/api/inter/tccFbaBoxUp/getBoxRoleEditInfo',
			  data : {bid:$('#bid').val()},
			  type : 'POST',
			  async : false,//关闭异步
			  success : function(result) {
				  console.log('----- result ------',result);
				  if (result.code == '0') {
				  	var date = result.date;

				  	if(isSearch==0){
						isEdit = date.isEdit;//是否可编辑 0否、1是
						$('#topTip').text(date.tipMsg);
					}
				  	if(isEdit == 0 ){
						$('#autoInputNum').hide();
					}

				  	if(date.printTip!=null && date.printTip!=''){
						$('#printTip').html(date.printTip);
					}else {
						$('#printTip').hide();
					}

					  $('#boxNum').val(date.boxNum);//箱子数量
					  if(date.boxNumIsEdit == 0){//箱子数量是否可编辑 0否、1是
						  $('#boxNum').attr('readonly',1);
					  }
					  boxNumMax = date.boxNumMax;//最大箱子数
					  if(date.userId){
						  $('#boxUpUserId').val(date.userId);//装箱人工号
						  $('#boxUpUserName').val(date.userId + '/' + date.userName);//装箱人
					  }

					  dataList = date.dataList;
					  dataListByBox = date.dataListByBox;
					  console.log('----- dataList ------',dataList);
					  console.log('----- dataListByBox ------',dataListByBox);
				  }else{
					  layer.msg(result.msg);
				  }
			  }
		  });




		  /*
		  var dataList = [
			  {
				  commodityCode:'111',//商品编码
				  commodityName:'商品名称',//商品名称
				  sku:'sku',//sku
				  fnSku:'fnSku',//fnSku
				  boxUpNum:'111',//包装组数量
				  box1:5
			  }
		  ];

		  var dataListByBox = [
			  {
				  boxLong:'111',
				  boxWide:'2',
				  boxHigh:'3',
				  boxWeight:'4',
				  box1:1,
				  box2:0,
				  box3:1,
			  },
		  ];
		  */


		  if(isEdit == 0){
			  $('#topBtn').hide();
			  $('#topTip').show();
			  $('#boxNum').attr('readonly',1);
		  }else {
			  $('#topBtn').show();
			  $('#topTip').hide();
		  }

		  var cols =[];
		  var colsByGeneral = [];
		  var colsByBox =[];
		  var colsBoxByGeneral = [];

		  reSetCol();

		  //更新表头数据信息
		  boxNumChange();

		  layui.config({
				//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
				base: '/static/js/layui_extends/'
			}).use(['form', 'element', 'table', 'dropdown', 'util', 'laydate', 'upload', 'YsModal'], function(){
					  var element = layui.element;
					  var table = layui.table;
					  var dropdown = layui.dropdown;
					  var form = layui.form;
					  var util = layui.util;
					  var $ = layui.jquery;
					  var laydate = layui.laydate;
					  var upload = layui.upload;
			  			var input = layui.input;

					  // 创建渲染实例
					  table.render({
						  id:'main_table'
						  ,elem: '#main_table'
						  ,data:dataList
						  ,toolbar: ''//工具栏
						  ,defaultToolbar: [ 'filter',{
							  title: '刷新页面'
							  ,layEvent: 'LAYTABLE_REFRESH'
							  ,icon: 'layui-icon-refresh'
						  }]
						  //,height: window.innerHeight - 70 // 最大高度减去其他容器已占有的高度差
						  ,where: {}
						  ,cellMinWidth: 95
						  ,limit : 500
						  //,limits : [20,50,200,500]
						  ,page: false
						  // ,request: {
							//   pageName: 'page',
							//   limitName: 'size'
						  // }
						  //,skin: 'row'
						  ,even: false // 开启隔行背景
						  ,skin: 'grid'//设置表格边框风格
						  ,cols:cols
						  ,done: function(res){
							  //监听滚动条
							  listenerScroll();
							  layui.form.render();

							  //监听输入框
							  $('input[name=boxNum]').on('change', function() {
								  var value = $(this).val(); // 获取输入值
								  var index = $(this).parents('tr').data('index'); // 获取行索引
								  var boxNum = $(this).attr('boxNum');//箱子号
								  console.log('Changed value:', value, 'at index:', index, 'boxNum:', boxNum);
								  dataList[index]['box'+boxNum] = value;
								  //重新加载表格数据
								  //table.reloadData('main_table');
								  //计算美规
								  dataList[index]['USAbox'+boxNum] = (parseFloat(value)*2.205).toFixed(2);
							  });

						  }
						  ,error: function(res, msg){
							  console.log(res, msg)
						  }
					  });

					  // 创建渲染实例
					  table.render({
						  id:'box_table'
						  ,elem: '#box_table'
						  //,url:'/api/inter/knowledgeType/searchType' // 此处为静态模拟数据，实际使用时需换成真实接口
						  ,data:dataListByBox
						  ,toolbar: (isEdit=='1'?'#toolbarDemo':'')
						  //,toolbar: ''//工具栏
						  ,defaultToolbar: []
						  //,height: window.innerHeight - 70 // 最大高度减去其他容器已占有的高度差
						  ,where: {id:'111'}
						  ,cellMinWidth: 95
						  ,limit : 500
						  //,limits : [20,50,200,500]
						  ,page: false
						  ,request: {
							  pageName: 'page',
							  limitName: 'size'
						  }
						  //,skin: 'row'
						  ,even: false // 开启隔行背景
						  ,skin: 'grid'//设置表格边框风格
						  ,cols:colsByBox
						  ,done: function(res){
							  //监听滚动条
							  listenerScroll();
							  layui.form.render();

							  //监听输入框
							  $('input[name=boxLong]').on('change', function() { //
								  var value = $(this).val(); // 获取输入值
								  var index = $(this).parents('tr').data('index'); // 获取行索引
								  console.log('Changed value:', value, 'at index:', index);
								  dataListByBox[index]['boxLong'] = value;
								  //重新加载表格数据
								  //table.reloadData('box_table');
								  dataListByBox[index]['USAboxLong'] = (parseFloat(value)*0.3937008).toFixed(2);
							  });

							  //监听输入框
							  $('input[name=boxWide]').on('change', function() { //
								  var value = $(this).val(); // 获取输入值
								  var index = $(this).parents('tr').data('index'); // 获取行索引
								  console.log('Changed value:', value, 'at index:', index);
								  dataListByBox[index]['boxWide'] = value;
								  dataListByBox[index]['USAboxWide'] = (parseFloat(value)*0.3937008).toFixed(2);
								  //重新加载表格数据
								  //table.reloadData('box_table');
							  });

							  //监听输入框
							  $('input[name=boxHigh]').on('change', function() { //
								  var value = $(this).val(); // 获取输入值
								  var index = $(this).parents('tr').data('index'); // 获取行索引
								  console.log('Changed value:', value, 'at index:', index);
								  dataListByBox[index]['boxHigh'] = value;
								  dataListByBox[index]['USAboxHigh'] = (parseFloat(value)*0.3937008).toFixed(2);
								  //重新加载表格数据
								  //table.reloadData('box_table');
							  });


						  }
						  ,error: function(res, msg){
							  console.log(res, msg)
						  }
					  });


					  // 获取当前行数据 - 自定义方法
					  table.getRowData = function(tableId, elem){
						  var index = $(elem).closest('tr').data('index');
						  return table.cache[tableId][index] || {};
					  };


					  // 获取所有行数据 - 自定义方法
					  table.getAllData = function(tableId){
						  return table.cache[tableId] || [];
					  };

					  // 工具栏事件
					  table.on('toolbar(box_table)', function(obj){
						  var id = obj.config.id;
						  var checkStatus = table.checkStatus(id);
                          var datas = checkStatus.data;
						  var othis = lay(this);
						  console.log('----- obj ------',obj);
						  switch(obj.event){
                              case 'add-data':
							  {
								  dataListByBox.push({});
								  //重新加载表格数据
								  table.reloadData('box_table');
								  break;
							  }
							  case 'del-data':
							  {
							  	if(datas==null || datas.length<=0){
									return layer.msg('请选择要删除的数据');
								}
								  for (var i = dataListByBox.length - 1; i >= 0; i--) {
									  var checkedStatus = dataListByBox[i]['LAY_CHECKED'];
									  if(checkedStatus){
										  dataListByBox.splice(dataListByBox[i]['LAY_TABLE_INDEX'], 1);
									  }
								  }
								  //重新加载表格数据
								  table.reloadData('box_table');
								  break;
							  }
						  };
					  });

					  // 单元格编辑事件
					  table.on('edit(main_table)', function(obj){
						  var field = obj.field; // 得到修改的字段
						  var value = obj.value; // 得到修改后的值
						  var data = obj.data; // 得到所在行所有键值
						  //console.log(obj); // 查看对象所有成员
						  //console.log('----- dataList ------',dataList);
						  // 更新当前缓存数据
						  var update = {};
						  update[field] = value;
						  obj.update(update, true); // 参数 true 为 v2.7 新增功能，即同步更新其他包含自定义模板并可能存在关联的列视图
					  });

					  // 单元格编辑事件
					  table.on('edit(box_table)', function(obj){
						  var field = obj.field; // 得到修改的字段
						  var value = obj.value; // 得到修改后的值
						  var data = obj.data; // 得到所在行所有键值
						  //console.log(obj); // 查看对象所有成员
						  //console.log('----- dataListByBox ------',dataListByBox);

						  // 更新当前缓存数据
						  var update = {};
						  update[field] = value;
						  obj.update(update, true); // 参数 true 为 v2.7 新增功能，即同步更新其他包含自定义模板并可能存在关联的列视图
					  });


					  // checkbox 事件
					  form.on('input(_input_filter_size_input_num_on_sub_grid)', function(obj){
							console.log('obj',obj);
					  });


					  // checkbox 事件
					  form.on('checkbox(_input_filter_checkbox_on_sub_grid)', function(obj){
					  	/*
						  var value = elem.value; // 获得 checkbox 值
						  var othis = data.othis; // 获得 checkbox 元素被替换后的 jQuery 对象
						  layer.msg('checked 状态: '+ elem.checked);
					  	 */
						  var elem = obj.elem; // 获得 checkbox 原始 DOM 对象
						  var checked = elem.checked; // 获得 checkbox 选中状态
						  var value = elem.value;
						  var boxNum = $(elem).attr('boxNum');//箱子号
						  var boxValue = 0;
						  if(elem.checked){//选中
							  boxValue = 1;
						  }
						  var value = obj.value; // 获取选中项 value
						  // 获取当前行数据(如 id 等字段，以作为数据修改的索引)
						  var data = table.getRowData('box_table', obj.elem);
						  data['box'+boxNum] = boxValue;
						  //console.log('----- data ------',data);
						  //console.log('----- dataListByBox ------',dataListByBox);
						  var index = data.LAY_TABLE_INDEX;
						  var allData = table.getAllData('box_table');
						  //console.log('----- allData ------',allData);
						  if(elem.checked){//选中时,纵列其他行改为非选中
							  for(var i=0;i<allData.length;i++){
								  if(allData[i].LAY_TABLE_INDEX!=index){
									  allData[i]['box'+boxNum] = 0;
								  }
							  }
							  //重新加载表格数据
							  table.reloadData('box_table');
						  }
						  //console.log('----- dataListByBox ------',dataListByBox);
					  });



					  form.on('checkbox(american-checkbox-filter)', function(data){
						  var elem = data.elem; // 获得 checkbox 原始 DOM 对象
						  var checked = elem.checked; // 获得 checkbox 选中状态
						  var value = elem.value; // 获得 checkbox 值
						  var othis = data.othis; // 获得 checkbox 元素被替换后的 jQuery 对象

						  layer.msg('checked 状态: '+ elem.checked);
					  });


		  });

		  
		  function americanChange() {
			  var boxNum = $('#boxNum').val();
			  if(!boxNum){
				  return layer.alert("请先填写箱子数量！");
			  }
		  	//开启
		  	if(americanChangeIsOpen==0){
				americanChangeIsOpen = 1;
		  		//表1修改
				const row = JSON.parse(JSON.stringify(dataList[dataList.length-1]));
				row.realityBoxUpNum = '重量（lb）';
				for(var boxIndex = 1;boxIndex<=boxNum;boxIndex++){
					row['box'+boxIndex] = row['USAbox'+boxIndex];
				}
				dataList.push(row);
				//刷新表格
				layui.table.reloadData('main_table');

				boxNumChange();
				reloadTableAll();
				layui.table.reload('box_table');

				$('#americanChangeBtnTxt').text('关闭美规界面');

			}else {
				americanChangeIsOpen = 0;
		  		//关闭
				dataList.pop();
				//刷新表格
				layui.table.reloadData('main_table');
				boxNumChange();
				reloadTableAll();
				layui.table.reload('box_table');

				$('#americanChangeBtnTxt').text('美规界面');

			}
			  
		  }

		  //自动装箱
		  function autoInputNumBtn(){
			  var boxNum = $('#boxNum').val();
			  if(!boxNum){
				  return layer.alert("请先填写箱子数量！");
			  }
			  for(var i=0;i<dataList.length;i++){
			  	var row = dataList[i];
			  	if(row.numOrWeight == 'num'){
					var countNum = Math.round(parseFloat(row.boxUpNum)/parseFloat(boxNum));
					for(var boxIndex = 1;boxIndex<=boxNum;boxIndex++){
						dataList[i]['box'+boxIndex] = countNum;
					}
				}
			  }
			  //计算数量总计
			  for(var i=0;i<dataList.length;i++){
				  if(dataList[i].numOrWeight == 'num'){
					  var count = 0;
					  for(var boxIndex = 1;boxIndex<=boxNum;boxIndex++){
						  count += parseInt(dataList[i]['box'+boxIndex]);
					  }
					  dataList[i]['realityBoxUpNum'] = count;
				  }
			  }

			  //计算总计
			  for(var boxIndex = 1;boxIndex<=boxNum;boxIndex++){
				  var count = 0;
				  for(var i=0;i<dataList.length;i++){
					  if(dataList[i].numOrWeight == 'num'){
						  count += parseInt(dataList[i]['box'+boxIndex]);
					  }
				  }
				  for(var i=0;i<dataList.length;i++){
					  if(dataList[i].numOrWeight == '0'){
						  dataList[i]['box'+boxIndex] = count;
					  }
				  }

			  }
			  //刷新表格
			  layui.table.reloadData('main_table');

		  }

		  //滚动条设置
		  function listenerScroll() {
		  	//隐藏第一个表的横向滚动条
			  $('.layui-table-view-1').find('.layui-table-body').addClass('hide-scrollbar');
			  //两个表格滚动条同步滚动
			  $('.layui-table-body').on('scroll', function(){
				  // 获取滚动条的位置
				  var scrollLeft = $(this).scrollLeft();
				  //console.log('横向滚动位置：', scrollLeft);
				  $('.layui-table-body').scrollLeft(scrollLeft);
			  });
		  }

		  //箱子数量变更
		  function boxNumChange() {
			  var boxNum = $('#boxNum').val();//获取箱子数量
			  if(boxNum>boxNumMax){
				  layer.msg('最大箱子数为：'+boxNumMax);
				  boxNum = boxNumMax;
			  }
			  boxNum = parseInt(boxNum);
			  $('#boxNum').val(boxNum);
			  if(americanChangeIsOpen==1){
				  reSetColByUSA();
			  }else{
				  reSetCol();
			  }


			  var colsByGeneralTotal = colsByGeneral;
			  var colsBoxByGeneralTotal = colsBoxByGeneral;

			  if(boxNum>0){
				  //for(var i=0;i<boxCodeArr.length;i++){
				 for(var i=1;i<=boxNum;i++){
					  colsByGeneralTotal.push(
							  //{title: '箱子'+i, width: '80' , field:'box'+i, align:"center",edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'}
							 {title: '箱子'+i, width: '80' , field:'box'+i, align:"center",
									 templet: '<div class="layui-form"><input type="number" class="layui-input" style="text-align: center;" boxNum="'+i+'" lay-skin="primary" name="boxNum" value="{{d[\'box\'+'+i+']}}" '
							 	//+'  lay-filter="_input_filter_input_num_on_sub_grid" '+(isEdit==0?'readonly':'')+' '+'{{d[\'numOrWeight\']?\'\':\'readonly\'}}' + '></div>'
											 +'  lay-filter="_input_filter_input_num_on_sub_grid" '+(isEdit==0 ?'readonly':'')+'></div>'
							 },
					  );
					  colsBoxByGeneralTotal.push(
							  {title: '箱子'+i, width: '80' , field:'box'+i, align:"center",
								  templet: '<div class="layui-form"><input type="checkbox" boxNum="'+i+'" lay-skin="primary" name="'+'box'+i+'" value="{{d[\'box\'+'+i+']}}" '
										  +'{{d[\'box\'+'+i+']?\'checked\':\'\'}}'+'  lay-filter="_input_filter_checkbox_on_sub_grid" '+(isEdit==0?'disabled':'')+'></div>'
							  },
					  );
				  }
			  }

			  cols = [];
			  cols.push(colsByGeneralTotal);
			  colsByBox =[];
			  colsByBox.push(colsBoxByGeneralTotal);
			  layui.form.render('checkbox');
		  }

		  //箱子数量变更 + 表格刷新
		  function boxNumChangeAndReload() {
			  boxNumChange();
			  reloadTableAll();
		  }

		  //重新加载表格
		  function reloadTableAll() {
			  layui.table.reload('main_table', {
				  cols:cols
			  });
			  layui.table.reload('box_table', {
				  cols:colsByBox
			  });
		  }

		  //弹出层
		  function chooseModel() {
			  if(isEdit==1){
				  // 打开单选框
				  layui.YsModal.init({modalKey: 'TS_UserInfo', colCode: 'userId', parentObj: window,extraData:'',conditionsDefault: [{code: 'deptName', value:'仓储部'}],})
			  }

			  //return;
		  }
		  //弹出层回调
		  function matchValuesAfterModalSelectRadio(colCode, data,extraData) {
			  if (data == "none" || !data) {//没有选中时
				  layer.msg("请选择！", {icon: 7});
			  } else {
				  $('#boxUpUserId').val(data.userId);
				  $('#boxUpUserName').val(data.userId + '/' + data.userName );
			  }
		  }


		  function reSetCol() {
			  colsByGeneral = [
				  {title: '', type: 'checkbox',fixed:'left',  unresize: true, width: '40'},
				  {title: '序号',   align:"center",fixed:'left',type:"numbers"},
				  {title: '商品编码',   width: '100' , field:'commodityCode' ,align:"center",fixed:'left'},
				  {title: '商品名称',   width: '100' , field:'commodityName' ,align:"center",fixed:'left'},
				  {title: 'SKU', width: '100' , field:'sku', align:"center",fixed:'left'},
				  {title: 'FNSKU', width: '100' , field:'fnSku', align:"center",fixed:'left'},
				  {title: '采购单价', width: '100' , field:'purchaseAmount', align:"center",fixed:'left'},
				  {title: '均分装箱数量', width: '100' , field:'averageBoxUpNum', align:"center",fixed:'left'},
				  {title: '包装组数量', width: '100' , field:'boxUpNum', align:"center",fixed:'left'},
				  {title: '数量总计', width: '100' , field:'realityBoxUpNum', align:"center",fixed:'left',
					  templet: function(d){
						  var str = '<div>' + d.realityBoxUpNum + '   </div>';
						  if(d.realityBoxUpNum != d.boxUpNum && d.numOrWeight == 'num'){
							  str =  '<div style="color: red;">' + d.realityBoxUpNum + '   </div>';
						  }
						  return str;
					  }
				  },

			  ];
			  colsBoxByGeneral = [
				  {title: '', type: 'checkbox',  unresize: true, width: '40',fixed:'left'},
				  {title: '序号',   align:"center",type:"numbers",fixed:'left'},
				  {title: '抛重（物流/快递）', width: '150' , field:'throwingWeight', align:"center",fixed:'left'},
				  {title: '包装尺寸',   width: '350' , field:'sizeTxt' ,align:"center",fixed:'left',
					  templet: function(d){
						  var sizeTxt = '';
						  if(d.boxLong || d.boxLong==0) sizeTxt = d.boxLong;
						  if(d.boxWide || d.boxWide==0) sizeTxt += '*'+d.boxWide;
						  if(d.boxHigh || d.boxHigh==0) sizeTxt += '*'+d.boxHigh;
						  //if(d.boxWeight || d.boxWeight==0) sizeTxt += '*'+d.boxWeight;
						  return '<div>' + sizeTxt + '   </div>';
					  }
				  },
				  //{title: '长（cm）',   width: '100' , field:'boxLong' ,align:"center",fixed:'left',edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'},
				  //{title: '宽（cm）', width: '100' , field:'boxWide', align:"center",fixed:'left',edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'},
				  //{title: '高（cm）', width: '100' , field:'boxHigh', align:"center",fixed:'left',edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'},
				  //{title: '重量（kg）', width: '156' , field:'boxWeight', align:"center",fixed:'left',edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'},

				  {title: '长（cm）', width: '100' , field:'boxLong', align:"center",fixed:'left',
					  templet: '<div class="layui-form"><input type="number" class="layui-input" style="text-align: center;" lay-skin="primary" name="boxLong" value="{{d[\'boxLong\']}}" '
							  +'  lay-filter="_input_filter_size_input_num_on_sub_grid" '+(isEdit==0?'readonly':'')+'></div>'
				  },
				  {title: '宽（cm）', width: '100' , field:'boxWide', align:"center",fixed:'left',
					  templet: '<div class="layui-form"><input type="number" class="layui-input" style="text-align: center;" lay-skin="primary" name="boxWide" value="{{d[\'boxWide\']}}" '
							  +'  lay-filter="_input_filter_size_input_num_on_sub_grid" '+(isEdit==0?'readonly':'')+'></div>'
				  },
				  {title: '高（cm）', width: '100' , field:'boxHigh', align:"center",fixed:'left',
					  templet: '<div class="layui-form"><input type="number" class="layui-input" style="text-align: center;" lay-skin="primary" name="boxHigh" value="{{d[\'boxHigh\']}}" '
							  +'  lay-filter="_input_filter_size_input_num_on_sub_grid" '+(isEdit==0?'readonly':'')+'></div>'
				  },

			  ];


		  }




		  function reSetColByUSA() {
			  colsByGeneral = [
				  {title: '', type: 'checkbox',fixed:'left',  unresize: true, width: '40'},
				  {title: '序号',   align:"center",fixed:'left',type:"numbers"},
				  {title: '商品编码',   width: '100' , field:'commodityCode' ,align:"center",fixed:'left'},
				  {title: '商品名称',   width: '100' , field:'commodityName' ,align:"center",fixed:'left'},
				  {title: 'SKU', width: '100' , field:'sku', align:"center",fixed:'left'},
				  {title: 'FNSKU', width: '100' , field:'fnSku', align:"center",fixed:'left'},
				  {title: '采购单价', width: '100' , field:'purchaseAmount', align:"center",fixed:'left'},
				  {title: '均分装箱数量', width: '100' , field:'averageBoxUpNum', align:"center",fixed:'left'},
				  {title: '包装组数量', width: '100' , field:'boxUpNum', align:"center",fixed:'left'},
				  {title: '数量总计', width: '100' , field:'realityBoxUpNum', align:"center",fixed:'left',
					  templet: function(d){
						  var str = '<div>' + d.realityBoxUpNum + '   </div>';
						  if(d.realityBoxUpNum != d.boxUpNum && d.numOrWeight == 'num'){
							  str =  '<div style="color: red;">' + d.realityBoxUpNum + '   </div>';
						  }
						  return str;
					  }
				  },

			  ];
			  colsBoxByGeneral = [
				  {title: '', type: 'checkbox',  unresize: true, width: '40',fixed:'left'},
				  {title: '序号',   align:"center",type:"numbers",fixed:'left'},
				  {title: '抛重（物流/快递）', width: '120' , field:'throwingWeight', align:"center",fixed:'left'},
				  {title: '包装尺寸',   width: '200' , field:'sizeTxt' ,align:"center",fixed:'left',
					  templet: function(d){
						  var sizeTxt = '';
						  if(d.boxLong || d.boxLong==0) sizeTxt = d.boxLong;
						  if(d.boxWide || d.boxWide==0) sizeTxt += '*'+d.boxWide;
						  if(d.boxHigh || d.boxHigh==0) sizeTxt += '*'+d.boxHigh;
						  //if(d.boxWeight || d.boxWeight==0) sizeTxt += '*'+d.boxWeight;
						  return '<div>' + sizeTxt + '   </div>';
					  }
				  },
				  //{title: '长（cm）',   width: '100' , field:'boxLong' ,align:"center",fixed:'left',edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'},
				  //{title: '宽（cm）', width: '100' , field:'boxWide', align:"center",fixed:'left',edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'},
				  //{title: '高（cm）', width: '100' , field:'boxHigh', align:"center",fixed:'left',edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'},
				  //{title: '重量（kg）', width: '156' , field:'boxWeight', align:"center",fixed:'left',edit: (isEdit==1?'text':false),style:'background-color:#E1EFFA;'},

				  {title: '长（cm）', width: '80' , field:'boxLong', align:"center",fixed:'left',
					  templet: '<div class="layui-form"><input type="number" class="layui-input" style="text-align: center;" lay-skin="primary" name="boxLong" value="{{d[\'boxLong\']}}" '
							  +'  lay-filter="_input_filter_size_input_num_on_sub_grid" '+(isEdit==0?'readonly':'')+'></div>'
				  },
				  {title: '长（in）', width: '80' , field:'USAboxLong', align:"center",fixed:'left'},
				  {title: '宽（cm）', width: '80' , field:'boxWide', align:"center",fixed:'left',
					  templet: '<div class="layui-form"><input type="number" class="layui-input" style="text-align: center;" lay-skin="primary" name="boxWide" value="{{d[\'boxWide\']}}" '
							  +'  lay-filter="_input_filter_size_input_num_on_sub_grid" '+(isEdit==0?'readonly':'')+'></div>'
				  },
				  {title: '宽（in）', width: '80' , field:'USAboxWide', align:"center",fixed:'left'},
				  {title: '高（cm）', width: '80' , field:'boxHigh', align:"center",fixed:'left',
					  templet: '<div class="layui-form"><input type="number" class="layui-input" style="text-align: center;" lay-skin="primary" name="boxHigh" value="{{d[\'boxHigh\']}}" '
							  +'  lay-filter="_input_filter_size_input_num_on_sub_grid" '+(isEdit==0?'readonly':'')+'></div>'
				  },
				  {title: '高（in）', width: '80' , field:'USAboxHigh', align:"center",fixed:'left'},

			  ];


		  }



		  //保存
		  function formSubmit() {

			  var loadIndex = layer.load(0);

			  //var tableId = parent.window.c.id_table_main;

			  //获取列表数据
			  $.ajax({
				  url : '/api/inter/tccFbaBoxUp/saveBoxRoleEditInfo',
				  data : {
				  	bid:$('#bid').val(),//单号
					  boxUpUserId:$('#boxUpUserId').val(),//装箱人
					  boxNum:$('#boxNum').val(),//箱子数量
					  dataList : JSON.stringify(dataList),//表1详情数据
					  dataListByBox : JSON.stringify(dataListByBox),//表2详情数据

				  },
				  type : 'POST',
				  async : false,//关闭异步
				  success : function(result) {
					  //console.log('----- result ------',result);
					  if (result.code == '0') {
						  //layui.table.reloadData(tableId);
						  layer.msg(result.msg);
						  setTimeout(function(){
							  //parent.window.layer.closeAll();
							  parent.window.layui.table.reloadData(tableId);
							  //parent.window.layer.closeAll();
							  //parent.window.location.reload();
							  window.location.reload();
						  }, 2000);

						  //
						  // //重新获取列表数据
						  // $.ajax({
							//   url : '/api/inter/tccFbaBoxUp/getBoxRoleEditInfo',
							//   data : {bid:$('#bid').val()},
							//   type : 'POST',
							//   async : false,//关闭异步
							//   success : function(result) {
							// 	  console.log('----- result ------',result);
							// 	  if (result.code == '0') {
							// 		  var date = result.date;
							// 		  dataList = date.dataList;
							// 		  dataListByBox = date.dataListByBox;
							// 		  //重新加载表格数据
							// 		  layui.table.reloadData('main_table');
							// 		  layui.table.reloadData('box_table');
							// 		  layui.form.render();
							// 	  }else{
							// 		  layer.msg(result.msg);
							// 	  }
							//   }
						  // });

					  }else{
						  layer.alert(result.msg);
					  }
				  }
			  });

			  layer.close(loadIndex);
		  }

      </script>

  </body>
</html>